package com.lishuang.system.service.impl;

import com.lishuang.basic.mapper.BaseMapper;
import com.lishuang.basic.service.impl.BaseServiceImpl;
import com.lishuang.system.domain.DictionaryType;
import com.lishuang.system.mapper.DictionaryTypeMapper;
import com.lishuang.system.service.IDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DictionaryTypeServiceImpl extends BaseServiceImpl<DictionaryType> implements IDictionaryTypeService {

    @Autowired
    private BaseMapper<DictionaryType> baseMapper;

    @Autowired
    private DictionaryTypeMapper dictionaryTypeMapper;


    @Override
    @Transactional
    public void save(DictionaryType dictionaryType) {
        System.out.println(dictionaryTypeMapper.loadBySn(dictionaryType.getSn())+"1111111111111111111111111111");
        if (dictionaryTypeMapper.loadBySn(dictionaryType.getSn())>0) {
            throw new RuntimeException("操作失败，编码重复，请修改。。。");
        }else {
            super.save(dictionaryType);
        }

    }

    @Override
    @Transactional
    public void update(DictionaryType dictionaryType) {

        if (dictionaryTypeMapper.loadBySn(dictionaryType.getSn())>0) {
            throw new RuntimeException("操作失败，编码重复，请修改。。。");
        }else {
            super.update(dictionaryType);
        }

    }


    @Override
    @Transactional
    public void removeByTypeId(Long id) {
        dictionaryTypeMapper.removeByTypeId(id);
    }

    @Override
    public void batchDeleteByTypeIds(List<Long> ids) {
        dictionaryTypeMapper.batchDeleteByTypeIds(ids);
    }
}
